package Zoo.handler;


import Zoo.entity.ZoomenEntity;
import Zoo.impl.LeaderService1Impl;
import Zoo.service.LeaderService1;
import Zoo.view.leaderview.AddZoomenView;
import Zoo.view.leaderview.LeaderView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 园长增加动物饲养员
 */
public class AddZoomenViewHandler implements ActionListener {
    private AddZoomenView addZoomenView;
    private LeaderView1 leaderView1;

    public AddZoomenViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1) {
        this.addZoomenView = addZoomenView;
        this.leaderView1 = leaderView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
        String text = jButton.getText();
        if ("添加".equals(text)) {
            LeaderService1 leaderService1 = new LeaderService1Impl();
            ZoomenEntity zoomenEntity = addZoomenView.buildZoomenEntity();
            boolean addResult = leaderService1.add(zoomenEntity);
            if (addResult) {
                //重新加载表格查到最新数据
                leaderView1.reloadTable();
                addZoomenView.dispose();
            } else {
                JOptionPane.showMessageDialog(addZoomenView, "添加失败");

            }

        }
    }

}
